<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
// use App\User;

class ApiController extends Controller
{


    public function __construct(Request $request)
    {   

        if ( JWTAuth::getToken() ){
            try{
                // $user = User::find(8);
                $user = JWTAuth::parseToken()->authenticate();

                if ( !$user || !$user->exists ){
                    return parent::error('invalid_credentials');
                }

                $this->user = $user;
            }catch(JWTException $e){
                return parent::error($e->getMessage());
            }
        }
    }

    
}
